package org.zjt;

import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.zjt.domain.Person;
import org.zjt.domain.PersonDto;

@SpringBootApplication
@ServletComponentScan(basePackages = "org.zjt.servlet3")
public class BootServletFilterApplication {

	public static void main(String[] args) {
		SpringApplication.run(BootServletFilterApplication.class, args);
	}

	@Bean
	public MapperFactory beanMapperFactory(){
		MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
		mapperFactory.classMap(Person.class, PersonDto.class)
				.field("name.first", "firstName")
				.field("name.last", "lastName")
				// knownAliases{first} list中的Namme.first  为 aliases中元素第1个元素。
				// knownAliases{first} list中的Namme.last   为 aliases中元素第2个元素。
				.field("knownAliases{first}", "aliases{[0]}")
				.field("knownAliases{last}", "aliases{[1]}")
				.byDefault()
				.register();
		return mapperFactory;
	}
}
